package com.shareach.web.util;

import java.util.Date;

import org.springframework.context.ApplicationContext;

import com.mongodb.MongoException;
import com.shareach.domain.BaseBankDomain;
import com.shareach.domain.BaseCategoryDomain;
import com.shareach.domain.BaseCityDomain;
import com.shareach.domain.BaseZoomDomain;
import com.shareach.service.BaseBankService;
import com.shareach.service.BaseCategoryService;
import com.shareach.service.BaseCityService;
import com.shareach.service.BaseZoomService;
import com.shareach.util.ContextConf;
import com.shareach.util.DateUtils;

public class VTool {
	private BaseCityService cityService;
	private BaseZoomService zoomService;
	private BaseBankService bankService;
	private BaseCategoryService categoryService;

	// public String getWXOrderStatus(int code){
	// return WXOrderStatus.getStr(code);
	// }
	// public String getUserModuleStatus(int code){
	// return UserModuleStatus.getStr(code);
	// }
	public String parseDate(Long time) {
		if (time == null)
			return "";
		return DateUtils.getDate(new Date(time), DateUtils.DATE_FORMAT);
	}

	public String parseTime(Long time) {
		if (time == null)
			return "";
		return DateUtils.getDate(new Date(time));
	}

	public String parseTime(Date date) {
		if (date == null)
			return "";
		return DateUtils.getDate(date);
	}

	public String parseDate(Date date) {
		if (date == null)
			return "";
		return DateUtils.getDate(date, DateUtils.DATE_FORMAT);
	}

	public String getCity(Long city) throws MongoException, Exception {
		if (null == city)
			return null;

		ApplicationContext context = ContextConf.getContext();
		cityService = context.getBean(BaseCityService.class);
		BaseCityDomain cd = cityService.getById(city);
		return (cd == null) ? "" : cd.getName();
	}

	public String getZoom(Long zoom) throws MongoException, Exception {
		if (null == zoom)
			return null;

		ApplicationContext context = ContextConf.getContext();
		zoomService = context.getBean(BaseZoomService.class);
		BaseZoomDomain bz = zoomService.getById(zoom);
		return (bz == null) ? "" : bz.getName();
	}

	public String getCategory(Long category) throws MongoException, Exception {
		if (null == category)
			return null;

		ApplicationContext context = ContextConf.getContext();
		categoryService = context.getBean(BaseCategoryService.class);
		BaseCategoryDomain bcd = categoryService.getById(category);
		return (bcd == null) ? "" : bcd.getName();
	}

	public String getBank(String bank) throws MongoException, Exception {
		if (null == bank)
			return null;

		ApplicationContext context = ContextConf.getContext();
		bankService = context.getBean(BaseBankService.class);
		BaseBankDomain bcd = bankService.getById(Long.valueOf(bank));
		return (bcd == null) ? "" : bcd.getName();
	}

	public String getBank(Long bank) throws MongoException, Exception {
		if (null == bank)
			return null;

		ApplicationContext context = ContextConf.getContext();
		bankService = context.getBean(BaseBankService.class);
		BaseBankDomain bcd = bankService.getById(bank);
		return (bcd == null) ? "" : bcd.getName();
	}

}
